<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of registrasi
 *
 * @author Andi
 */
include_once("database.php");
include_once("photo.php");

class registrasi extends database {
    //put your code here
    var $table = 'user';
    var $col_id = 'user_id';

    function  __construct() {
        $this->connect();
    }


    function register($user_name,$full_name,$password,$birthday,$location,$gender,$email,$url_photo,$wall_prev) {
        $photo = new photo();
        $photo->upload($user_name, 'profil picture', 'profil picture', '10-10-2010', 'profil picture', 'all_user', 'all_user', $url_photo);
        $target_path = "images/photos/" . $user_name . "/" . basename($url_photo['name']);
        $sql = "INSERT INTO user (user_name, full_name, password, birthday, location, gender, email, url_photo,wall_prev) VALUES ('$user_name','$full_name','$password','$birthday','$location','$gender','$email','$target_path','$wall_prev')";
        $this->query($sql);
    }

    function updateProfile($pil,$user_name,$new_val) {// 1->full_name, 2->password, 3->birthday, 4->location, 5->gender, 6->email, 7->url_photo, 8->wall_prev 9->online
        $sql = "SELECT * FROM user WHERE user_name = '$user_name'";
        $result = mysql_query($sql);
        $row = mysql_fetch_array($result);
        $id = $row['user_id'];
        if ($pil == 1) {
            $column_change = 'full_name';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else if ($pil == 2) {
            $column_change = 'password';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else if ($pil == 3) {
            $column_change = 'birthday';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else if ($pil == 4) {
            $column_change = 'location';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else if ($pil == 5) {
            $column_change = 'gender';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else if ($pil == 6) {
            $column_change = 'email';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else if ($pil == 7) {
            $photo = new photo();
            $photo->uploadProfPict($user_name, $new_val);
            $target_path = "images/photos/" . $user_name . "/" . basename($new_val['name']);
            $column_change = 'url_photo';
            $this->update($this->table, $this->col_id, $id, $column_change, $target_path);
        }else if ($pil == 8) {
            $column_change = 'wall_prev';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else if ($pil == 9) {
            $column_change = 'online';
            $this->update($this->table, $this->col_id, $id, $column_change, $new_val);
        }else {

        }
    }

    function updateProfPict($user_name, $urlPhoto) {
        $sql = "SELECT * FROM user WHERE user_name = '$user_name'";
        $result = mysql_query($sql);
        $row = mysql_fetch_array($result);
        $id = $row['user_id'];
        $column_change = 'url_photo';
        $this->update($this->table, $this->col_id, $id, $column_change, $urlPhoto);
    }

    function showProfile($user_name,$password) {
        $sql = "SELECT * FROM user WHERE user_name = '$user_name' AND password = '$password'";
        $result = mysql_query($sql);
        return $result;
    }

    function showLastRegistered(){
        $sql = "SELECT * FROM user ORDER BY user_id DESC";
        $result = mysql_query($sql);
        return $result;
    }
}


?>
